#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define BUF_SIZE 30

int main(int argc,char *argv[])
{
    int recv_sock;
    struct sockaddr_in addr;
    ssize_t str_len;
    char buf[BUF_SIZE];

    recv_sock = socket(AF_INET, SOCK_DGRAM, 0);
    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_port = htons((uint16_t)atoi(argv[1]));

    bind(recv_sock, (const struct sockaddr *)&addr, sizeof(addr));

    while(1) {
        str_len = recvfrom(recv_sock, buf, BUF_SIZE - 1, 0, NULL, 0);
        if(str_len < 0) {
            break;
        }
        buf[str_len]=0;
        fputs(buf, stdout);
    }
    close(recv_sock);
    return 0;
}